//
//  LogoutViewModel.swift
//  Exchange
//
//  Created by rui on 2018/6/5.
//  Copyright © 2018年 common. All rights reserved.
//

import UIKit

class LogoutViewModel: BaseViewModel {
    private lazy var logoutApi: LogoutRequest = {
        let logout = LogoutRequest()
        logout.dataReformer = self
        logout.paramSource = self
        logout.delegate = self
        return logout
    }()
    
    func logout() {
        let appInfo = AppInfo.default
        appInfo.isLogin = false
        self.logoutApi.loadData()
    }
}

extension LogoutViewModel: RequestCallBack,RequestDataReformer,RequestParamSource {
    
    func reform(_ request: BaseRequest, _ data: [String : Any]?) {
        if let _ = request as? LogoutRequest {
            self.response?(ResponseState.mine_logout,true, nil)
        }
    }
    
    func requestDidSucess(_ request: BaseRequest) {
        
    }
    
    func requestDidFail(_ request: BaseRequest) {
        if let _ = request as? LogoutRequest {
            self.response?(ResponseState.mine_logout,false, request.errorMsg)
        }
    }
    
    func requestParams(_ request: BaseRequest) -> [String : Any]? {
        return nil
    }
    
}
